<style lang="less">
    .current{
        .card-title{
            display: inline-block;
            width: 100%;
            height: 24px;
            line-height: 24px;
            font-size: 14px;
            color: #1c2438;
            font-weight: 700;
            overflow: inherit;
            text-overflow: ellipsis;
            white-space: nowrap;
            
        }
    }
    .margin-top-10{
        margin-top: 10px;
    }
</style>
<template>
    <div class="current">
    
        <Row class="margin-top-10" :gutter="10">
            <Col :md="24" :lg="24">
                <Card :gutter="10">
                    <p slot="title" class="card-title">
                        <Row class="" :gutter="10">
                            <Col :md="4" :lg="2">
                                <div style="margin-top: 2px;">
                                    <Icon type="ios-pulse"></Icon>
                                    {{this.$route.meta.title}}
                                </div>
                            </Col>
                        </Row>
                    </p>
                    <div class="line-chart-con">
                        <Form :model="formBatch" label-position="left" :label-width="100">
                            <FormItem label="当期期号：">
                                <Input v-model="formBatch.issue" style="margin-right: 2px; width: 250px;" placeholder="请输入当期期号"></Input>
                            </FormItem>
                            <FormItem label="下期期号：">
                                <Input v-model="formBatch.next_issue" style="margin-right: 2px; width: 250px;" placeholder="请输入下期期号"></Input>
                            </FormItem>
                            <FormItem label="开奖号：">
                                <Input number v-model="formBatch.open_number[0]" style="margin-right: 2px; width: 40px;" placeholder="1"></Input>
                                <Input number v-model="formBatch.open_number[1]" style="margin-right: 2px; width: 40px;" placeholder="2"></Input>
                                <Input number v-model="formBatch.open_number[2]" style="margin-right: 2px; width: 40px;" placeholder="3"></Input>
                                <Input number v-model="formBatch.open_number[3]" style="margin-right: 2px; width: 40px;" placeholder="4"></Input>
                                <Input number v-model="formBatch.open_number[4]" style="margin-right: 2px; width: 40px;" placeholder="5"></Input>
                                <Input number v-model="formBatch.open_number[5]" style="margin-right: 2px; width: 40px;" placeholder="6"></Input>+
                                <Input number v-model="formBatch.open_number[6]" style="margin-right: 2px; width: 40px;" placeholder="7"></Input>
                                <span style="color:#57a3f3;">(开奖号为1-49不重复的数字)</span>
                            </FormItem>
                            <FormItem label="当期开奖时间：">
                                <DatePicker type="date" v-model="formBatch.open_time[0]"  placeholder="请输入日期" style="width: 120px"></DatePicker> - <TimePicker type="time" v-model="formBatch.open_time[1]" placeholder="请输入时间" style="width: 120px"></TimePicker>
                            </FormItem>
                            <FormItem label="下期开奖时间：">
                                <DatePicker type="date" v-model="formBatch.next_open_time[0]"  placeholder="请输入日期" style="width: 120px"></DatePicker> - <TimePicker type="time" v-model="formBatch.next_open_time[1]" placeholder="请输入时间" style="width: 120px"></TimePicker>
                            </FormItem>
                        </Form>
                        <Button style="" type="info" @click="add">添加</Button>
                        
                    </div>
                </Card>
            </Col>
            
        </Row>
    </div>
</template>

<script>

export default {
    components: {

    },
    data () {
        return {
            formBatch:{
                issue: "",
                next_issue: "",
                open_time: ["",""],
                next_open_time: ["",""],
                open_number: []
            }
        }
    },
    computed: {
        
    },
    mounted(){
        
    },
    methods: {
       add(){
           let open_number=[]
           let on=this.formBatch.open_number
           if(on.length==7){
               for(let i=0;i<on.length;i++){
                    for(let j=0;j<on.length;j++){
                        if(j!=i&&on[i]==on[j]){
                            this.$Message.error('开奖号不允许存在重复项');
                            return
                        }
                    }
                    if(on[i]>=1&&on[i]<=49){
                        if(on[i] >= 1&&on[i]<=9){
                            open_number[i]= "0" + on[i]
                        }else{
                            open_number[i]= on[i]
                        } 
                    }else{
                        this.$Message.error('请输入1-49的开奖号');
                        return
                    }
                }
           }else{
                this.$Message.error('请输入完整的开奖号');
                return
           }
           

           function gshdate(d){
                let date = new Date(d);
                let Y = date.getFullYear()
                let M = date.getMonth() + 1;
                let D = date.getDate();
                let h = date.getHours()
                let m = date.getMinutes()
                let s = date.getSeconds()
                if (M >= 1 && M <= 9) M = "0" + M;
                if (D >= 0 && D <= 9) D = "0" + D;
                if (h >= 0 && h <= 9) h = "0" + h;
                if (m >= 0 && m <= 9) m = "0" + m;
                if (s >= 0 && s <= 9) s = "0" + s;
                return `${Y}-${M}-${D}`
            }
            let data={
                issue: this.formBatch.issue,
                next_issue: this.formBatch.next_issue,
                open_time: `${gshdate(this.formBatch.open_time[0])} ${this.formBatch.open_time[1]}`,
                next_open_time: `${gshdate(this.formBatch.next_open_time[0])} ${this.formBatch.next_open_time[1]}`,
                open_number: `${open_number[0]},${open_number[1]},${open_number[2]},${open_number[3]},${open_number[4]},${open_number[5]}+${open_number[6]}`
            }
            this.$api.repeater(this,'addHk6',data).then(res=>{
                if(res.success==true){
                    this.$Notice.success({
                        title: '开奖成功'
                    });
                }else{
                    this.$Notice.error({
                        title: '开奖失败'
                    });
                }
            })
        }
    }
};
</script>
